
#include <stdio.h>

const float EPS = 0.00001; 
double sqrt(double x) { 
	if(x == 0) return 0; 
	double result = x; 
	double lastValue = 0;
	while(fabs(result - lastValue) > EPS) 
	{ 
		lastValue = result; 
		result = result / 2.0f + x / 2.0f / result; 
	}
 	return (double)result;
 }


 float sqrt_test(float x) { 
	if(x == 0) return 0; 
	float result = x; 
	float xhalf = 0.5f*result; 
	int i = *(int*)&result; 
	i = 0x5f375a86- (i>>1); // what the fuck? 
	result = *(float*)&i; 
	result = result*(1.5f-xhalf*result*result); // Newton step, repeating increases accuracy 
	result = result*(1.5f-xhalf*result*result); 
	return 1.0f/result; 
}



 int main (int argc, char *argv[])
 {
    double a = 2;

    double b = sqrt_1(10);
    printf("%lf 的 平方根 为 %lf \n",a,b);


    return 0;
 }